<template>
<div>
   <div  class="authBox">
    <!-- <img class="image" src="../../assets/logo_regUnit.png" alt=""> -->
    <div class="text">
        您的配偶<span class="red">
     {{msg}}
        </span>
        
        正在进行贵州银行贷款申请，需要您配合完成信息录入、数据授权及人脸识别，请点击下方按钮开始操作
    </div>
      <button @click="goMate" class="btn">立 即 开 始</button>
      <div class="authMsg">
        <span>温馨提示：</span>
        <span>
            请勿将微信链接转发或分享给其他人员，仅限配偶本人操作！
        </span>
      </div>
   </div>
   <!-- <div v-else>
     <div  class="authBox">
     <h2 class="Box">
      此授权链接已失效，请联系申请人重新发送！
     </h2>
     </div>
   </div> -->
  </div>
</template>

<script>
import Vue from 'vue';
import { Dialog } from 'vant';

// 全局注册
Vue.use(Dialog);

export default {
  
 name:'authData',
 data(){
    return {
      instId:'',
      stateData:true,
      personalFlag:'',
      stateDate:null,
      msg:''
    }
 },
 mounted(){
   this.getint()
    this.instId =  this.getParam('instId') || ''
         
    this.personalFlag = this.getParam('personalFlag') 
    
      ? this.$route.query.personalFlag
      : false;
      let that = this
       this.baseService
        .postForm(this.__ctx + "/cifPer/exp/getNameByInstId",{instId:this.instId})
        .then((data) => {
         if (data.isOk) {
          this.msg = data.data
         }else{
           this.abTools.toast(data.msg, "warn");
         }
         console.log(data);
        });
            this.baseService
                    .postForm(this.__ctx + "/cifPer/exp/queryRes", {instId:this.instId})
                    .then((res) => {
                     if (res.isOk) {
                      if (res.data.dataResults == '1' && res.data.faceResults == '1' && res.data.smsResults == '1') {
                         that.stateDate = true
                       
                      }else{
                        that.stateDate = false
                      }
                     }else{
                      that.stateDate = false
                     }
                    }).catch(()=>{
                      that.stateDate = false
                    })
                    
 },

methods:{
    getint() {
      // 获取token是http://localhost:8080/biz/loginBy/jwtForMobile（行内）参数是account默认wxApplets、audience默认Applets
      //微信银行 account/audience: wxBank, 手机银行 account/audience: mobileBank
      return new Promise((resolve) => {
        let defer = this.baseService.postForm(
          this.__ctx + "/biz/loginBy/jwtForMobile",
          {
            account: process.env.account, //默认
            audience: process.env.account, //默认
          }
        );
        defer.then((data) => {
          if (data.isOk) {
            resolve();
          } else {
            this.$vux.toast.show({
              type: "warn",
              text: data.msg,
            });
          }
        });
      });
    },
      getParam(name) {
        var locUrl = window.location.search.substr(1);
        var aryParams = locUrl.split("&");
        var rtn = "";
        for (var i = 0; i < aryParams.length; i++) {
          var pair = aryParams[i];
          var aryEnt = pair.split("=");
          var key = aryEnt[0];
          var val = aryEnt[1];
          if (key != name) continue;
          if (rtn == "") {
            rtn = val;
          } else {
            rtn += "," + val;
          }
        }
        return rtn;
      },
   goMate(){
     
   let oldtime = this.getParam('creatTime') || 0
   let newtime = new Date().getTime()
   if (oldtime && newtime-oldtime > 4* 60 * 60 * 1000) {
        // this.stateData = false
     Dialog.alert({
  title: '温馨提示',
  message: ' 此授权链接已失效，请联系申请人重新发送！',
   }).then(() => {
  // on close
   });
   return 
   }else if (oldtime && newtime-oldtime < 4* 60 * 60 * 1000 && this.stateDate == true)  {
     Dialog.alert({
  title: '温馨提示',
  message: ' 您已经完成信息录入和数据授权，无需重复操作！',
   }).then(() => {
  // on close
   });
    return 
   }
   else{
    //  this.stateData = true
      this.$router.push({
                        path:'/auth/authMate',  
                        query: {
                        instId : this.instId,
                        personalFlag:this.personalFlag  //参数
                        }
                    })
   }

   } 
}
}
</script>
<style lang="less" scoped>
.authBox {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-direction: column;
    margin: 50px 20px;
    .text{
        font-size: 15px;
        width: 70%;
        margin-top: 30px;
    }
    .btn{
        width: 140px;
        height: 30px;
        margin-top: 40px;
        background-color: rgb(204, 52, 0);
        color: #fdd;
    }
    .authMsg{
        display: flex;
        flex-direction: column;
        margin-top: 30px;
        font-size: 14px;
        width: 70%;
    }
    .Box{
     margin-top: 50%;
     
    }
    .image{
      width: 80%;
    }
    .red{
      color: red;
    }
}
</style>